/**
 * There are <a href="https://www.hdzhx.com">邯郸智讯</a> code generation
 */
package com.boxin.ims.modules.wechat.entity.praise;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.validator.constraints.Length;

import com.boxin.ims.modules.momarketing.entity.QRCode;
import com.boxin.ims.modules.wechat.entity.WechatMember;
import com.thinkgem.jeesite.common.persistence.BaseEntity;
import com.thinkgem.jeesite.modules.sys.entity.User;

/**
 * 赞活动Entity
 * @author Jakemanse
 * @version 2014-01-03
 */
@Entity
@Table(name = "wp_praise_activity")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class PraiseActivity extends BaseEntity {
	
	private static final long serialVersionUID = 1L;
	private Long id; 		// 编号
	private User user; 		// 用户
	private String name; 	// 所中奖的名称
	private WechatMember member;	//所属微信会员
	private QRCode qrCode;		//对应的二维码
	private String url; 	// 原始文件URL
	private String fileName;	//
	private String status;	// 0正常  1：已使用   2：已作废
	private Integer praiseCounts;		//所获得的赞数名次
	private Boolean win;		//是否中奖  
	private Date endTime;		//失效时间
	private Date updateTime;	//更新时间
	private String delFlag;	// 删除标记（0：正常；1：删除）
	private Date createTime;	// 创建日期
	private String remarks; // 备注
	
	private boolean valid;	//是否可用  ，过期
	
	@Transient
	private Date startTime;	//查询使用
	
	

	public PraiseActivity() {
		this.createTime = new Date();
	}

	public PraiseActivity(Long id){
		this();
		this.id = id;
	}
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	//@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_wechat_praise_praiseActivity")
	//@SequenceGenerator(name = "seq_wechat_praise_praiseActivity", sequenceName = "seq_wechat_praise_praiseActivity")
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@ManyToOne
	@JoinColumn(name="user_id")
	@NotFound(action = NotFoundAction.IGNORE)
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	@NotNull
	
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
	
	@Length(min=1, max=200)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	
	@NotNull
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@ManyToOne
	@JoinColumn(name="member_id")
	@NotFound(action = NotFoundAction.IGNORE)
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	@NotNull
	public WechatMember getMember() {
		return member;
	}

	public void setMember(WechatMember member) {
		this.member = member;
	}

	@ManyToOne
	@JoinColumn(name="qrcode_id")
	@NotFound(action = NotFoundAction.IGNORE)
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	@NotNull
	public QRCode getQrCode() {
		return qrCode;
	}

	public void setQrCode(QRCode qrCode) {
		this.qrCode = qrCode;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}


	public Integer getPraiseCounts() {
		return praiseCounts;
	}

	public void setPraiseCounts(Integer praiseCounts) {
		this.praiseCounts = praiseCounts;
	}

	public Boolean getWin() {
		return win;
	}

	public void setWin(Boolean win) {
		this.win = win;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	public String getDelFlag() {
		return delFlag;
	}

	public void setDelFlag(String delFlag) {
		this.delFlag = delFlag;
	}

	public String getRemarks() {
		return remarks;
	}

	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}


	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}
	
	
	
	@Transient
	public boolean isValid() {
		java.util.Calendar c1=java.util.Calendar.getInstance();
		java.util.Calendar c2=java.util.Calendar.getInstance();
		try {
			c1.setTime(new Date());
			c2.setTime(endTime);
		} catch (Exception e) {
			System.err.println("格式不正确");
			return true;
		}
		int result = c1.compareTo(c2);
		if (result > 0){	//c1>c2  过期
			return false;
		}
		
//		Date nowDate = new Date();
//		if(nowDate.getTime() > endTime.getTime()){
//			return false;
//		}
		return true;
		
	}

	public void setValid(boolean valid) {
		this.valid = valid;
	}

	
	
	
}


